"""
    登录验证码
"""

import requests
from api.login import LoginApi
from common.yaml_util import write_yaml, read_yaml


# # 发送请求
# response = requests.get("http://kdtx-test.itheima.net/api/captchaImage")

# # 查看响应
# print(response.status_code)
# print(response.headers)
# print(response.content)
# print(response.text)
# print(response.json())

class Test01_login:

    # # 前置处理
    # def setup_method(self):
    #     # 实例化接口对象
    #     print("开始")
    #     self.login_api = LoginApi()
    #
    # # 后置处理
    # def teardown_method(self):
    #     pass
    # 获取验证码

    def test01_verifyCode(self):
        # 获取验证码
        response = LoginApi().get_verify_code()
        print(response.text)
        print("状态码:",response.status_code)
        print("uuid:",response.json().get("uuid"))
        # 将uuid保存到extract.yaml中
        write_yaml({"uuid":response.json().get("uuid")})
        # 断言
        assert 200 == response.status_code
        assert '成功' in response.text
        assert 200 == response.json().get("code")

    def test02_login(self):
        # 登录
        login_data = {
            "username":"admin",
            "password":"HM_2023_test",
            "code":"2",
            "uuid":LoginApi().get_verify_code().json().get("uuid")
            }
        login_header = {"Content-Type": "application/json"}
        response = LoginApi().login(login_data=login_data, login_header=login_header)
        print(response.json())
        print("状态码:", response.status_code)
        print("token:",response.json().get("token"))
        # 将token保存到extract.yaml中
        write_yaml({"token":response.json().get("token")})

